import 'package:safetymonitor/app/components/custom_app_bar.dart';
import 'package:safetymonitor/app/components/custom_modele/custom_input_page.dart';
import 'package:safetymonitor/app/components/custom_modele/custom_select_page.dart';
import 'package:safetymonitor/app/components/custom_modele/custom_title_chart_page.dart';
import 'package:safetymonitor/app/components/custom_select_work_user_page.dart';
import 'package:safetymonitor/app/core/core.dart';
import 'package:safetymonitor/app/data/entities/home/duty/duty_schedule_config_entity.dart';
import 'package:safetymonitor/router/app_pages.dart';
import 'controller.dart';

///开始排班
class StartSchedulingPage extends StatelessWidget {
  StartSchedulingPage({super.key});

  final controller = Get.put(StartSchedulingController());

  @override
  Widget build(BuildContext context) {
    return GetBuilder<StartSchedulingController>(
        init: controller,
        builder: (controller) {
          return Scaffold(
            appBar: CustomAppBar(
              titleText: '排班',
            ),
            body: Container(
              color: const Color(0xFFF7FBFE),
              padding: EdgeInsets.symmetric(vertical: 12.w, horizontal: 14.w),
              child: ListView(
                children: [
                  CustomTitleChartPage(
                    title: '排班',
                    child: _tobWidget(),
                  ),
                  AppGaps.vGap30,
                ],
              ),
            ),
            bottomSheet: Container(
              width: double.infinity,
              color: Colors.white,
              padding: EdgeInsets.symmetric(horizontal: 16.w, vertical: 5.w),
              child: ElevatedButton(
                style: ElevatedButton.styleFrom(
                  backgroundColor: AppColors.blue_button,
                  shape: RoundedRectangleBorder(
                    borderRadius: BorderRadius.circular(22.r),
                  ),
                ),
                onPressed: controller.confirm,
                child: Text(
                  '确定',
                  style: TextStyle(
                    fontSize: 14.sp,
                    color: Colors.white,
                    fontWeight: FontWeight.w400,
                  ),
                ),
              ),
            ),
          );
        });
  }

  Widget _tobWidget() {
    return Column(
      children: [
        CustomSelectPage(
          isEnabled: true,
          isRequired: true,
          selectText: controller.shiftName,
          title: '班次名称',
          hintText: '请选择',
          onCallBack: () {
            Get.toNamed(Routes.scheduleConfigSelectionPage, arguments: {
              'isRadio': true,
            })?.then((value) {
              final List<DutyScheduleConfigEntity> selectedList =
                  value as List<DutyScheduleConfigEntity>;
              controller.shiftName = selectedList[0].scheduleName!;
              controller.shiftNameId = selectedList[0].id!;
              controller.update();
            });
          },
        ),
        CustomInputPage(
          title: '值班室电话：',
          isRequired: true,
          textInputType: TextInputType.number,
          isEnabled: true,
          text: controller.dutyPhone,
          hintText: '请输入',
          onCallBack: (value) {
            controller.dutyPhone = value;
          },
        ),
        CustomSelectPage(
          isEnabled: true,
          isRequired: true,
          selectText: controller.startDate == ''
              ? ''
              : '${controller.startDate}至${controller.endDate}',
          title: '值班日期',
          hintText: '请选择',
          onCallBack: () {
            controller.selectTime();
          },
        ),
        CustomSelectWorkUserPage(
            title: '值班人员',
            titleType: '班次类型',
            isEnabled: true,
            operatorType: 0,
            queryParameters: const {},
            dataList: controller.operatorLists,
            onCallBack: (value) {
              controller.operatorLists = value;
            }),
        CustomSelectWorkUserPage(
            title: '值班领导',
            titleType: '班次类型',
            isEnabled: true,
            operatorType: 1,
            queryParameters: const {},
            dataList: controller.operatorListsL,
            onCallBack: (value) {
              controller.operatorListsL = value;
            }),

      ],
    );
  }
}
